package tomcat_handler;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;

import IOTWeb.com.IOTMain;
import IOTWeb.com.utils.FileOption;
import IOTWeb.com.utils.H2ConnectionPool;
import IOTWeb.com.utils.ReadUtil;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

public class test extends HttpServlet  {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String i = req.getParameter("num");
		PrintWriter out = resp.getWriter();
		ReadUtil readUtil = new ReadUtil();
		FileOption fileOption = new FileOption();
		String fileName = "D:\\workspace\\mqttclient\\error.html";
        FileReader reader = new FileReader(fileName);//定义一个fileReader对象，用来初始化BufferedReader
        BufferedReader bReader = new BufferedReader(reader);//new一个BufferedReader对象，将文件内容读取到缓存
        StringBuilder sb = new StringBuilder();//定义一个字符串缓存，将字符串存放缓存中
        String s = "";
        while ((s =bReader.readLine()) != null) {//逐行读取文件内容，不读取换行符和末尾的空格
            sb.append(s + "\n");//将读取的字符串添加换行符后累加存放在缓存中
        }
        bReader.close();
        String str = sb.toString();

		if(i.equals("1")||i.equals("10000")) {
			Date date=new Date();
			System.out.println("The user asked for resource: " + "NonePage");
			System.out.println("error.html" + " start send");
			SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS"); 
			System.out.println("第"+i+"次时间为"+format.format(date));
		}
		out.write(str);
		out.flush();
		out.close();
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		super.doPost(req, resp);
	}

}
